package ;

import easelhx.display.Container;
import easelhx.display.Graphics;
import easelhx.display.Shadow;
import easelhx.display.Shape;
import easelhx.geom.Point;

/**
 * ...
 * @author 
 */

class Segment extends Container
{
	private var selectedColor:String;
	private var segWidth:Float;
	private var segHeight:Float;
	private var vy:Float = 0;
	private var vx:Float = 0;
	private var inner:Shape;

	public function new(segWidth:Float, segHeight:Float, selectedColor:String) 
	{
		super();
		this.segWidth = segWidth;
		this.segHeight = segHeight;
		this.selectedColor = selectedColor;
		
        this.inner = this.getSprite();
        this.addChild(this.inner);
        this.shadow = new Shadow('#000000', 1, 1, 5);
	}
	
	public function getSprite () : Shape 
	{
		var s:Shape = new Shape();
        var g:Graphics = s.graphics;
        g.setStrokeStyle(0);
        g.beginFill(this.selectedColor);
        var _x = -this.segHeight/2;
        var _y = -this.segHeight/2;
        var _w = this.segWidth + this.segHeight;
        var _h = this.segHeight;
        var tl = this.segHeight;
        var tr = this.segHeight;
        var br = this.segHeight;
        var bl = this.segHeight;
        g.endStroke();
        g.drawRoundRectComplex(_x, _y, _w, _h, tl/2, tr/2, br/2, bl/2);
        g.endFill();
        g.beginStroke(Graphics.getRGB(0,0,0));
        g.drawCircle(0, 0, 2);
        g.endStroke();
        g.beginStroke(Graphics.getRGB(0,0,0));
        g.drawCircle(this.segWidth, 0, 2);
        g.endStroke();
        return s;
	}
	
	public function getPoint ():Point 
	{
		var angle:Float = this.rotation * Math.PI / 180;
        return new Point(this.x + Math.cos(angle)*this.segWidth, this.y + Math.sin(angle)*this.segWidth);
	}
	
}